package com.test.common.entity.perf;

import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "t_perf_resource", uniqueConstraints = @UniqueConstraint(columnNames = "objectId"))
public class PerfResourceEntity {

    public PerfResourceEntity() {}

    public PerfResourceEntity(String name, String creator, String objectId, long size) {
        this.name = name;
        this.creator = creator;
        this.objectId = objectId;
        this.createTime = new Date();
        this.modifyTime = new Date();
        this.size = size;
    }

    // 更新的方法
    public PerfResourceEntity(int id, String name, String creator, String objectId, long size) {
        this.id = id;
        this.name = name;
        this.creator = creator;
        this.objectId = objectId;
        this.modifyTime = new Date();
        this.size = size;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    @Column(columnDefinition = "VARCHAR(65) NOT NULL DEFAULT '' COMMENT '任务名称' ")
    private String name;

    @Column(columnDefinition = "VARCHAR(32) NOT NULL DEFAULT 'TODO' COMMENT '任务创建人，如：张三'")
    private String creator;

    @Column(columnDefinition = "VARCHAR(32) NOT NULL COMMENT '资源 Mongo ID'")
    private String objectId;

    @Column(columnDefinition = "DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '任务创建时间'")
    private Date createTime = new Date();

    @Column(columnDefinition = "DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '任务修改时间'")
    private Date modifyTime = new Date();

    @Column(columnDefinition = "int(11) NOT NULL COMMENT '文件大小 KB'")
    private long size;

    @Transient
    private String content;
}
